﻿using mozhi.smarterp.Finance.Enums;
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Domain.Entities;

namespace mozhi.smarterp.Finance.Logs
{
    public class OperationLog : AggregateRootBase<Guid>
    {
        public Guid? OperatorId { private set; get; }

        public string OperatorName { private set; get; }

        public OperationType Type { private set; get; }

        /// <summary>
        /// 模块代码
        /// </summary>
        public string ModuleCode {  private set; get; }

        /// <summary>
        /// 模块名称
        /// </summary>
        public string ModuleName { private set; get; }


        public Guid ObjectId { private set; get; }

        public string ObjectName { private set; get; }

        public string Comment { private set; get; }

        public List<OperationLogItem> Items { private set; get; }

        private OperationLog() { }

        public OperationLog(Guid id , Guid? operatorId, string operatorName, OperationType type, string moduleCode, string moduleName , Guid objectId, string objectName, string comment)
        {
            Id = id;
            OperatorId = operatorId;
            OperatorName = operatorName;
            Type = type;
            ModuleCode = moduleCode;
            ModuleName = moduleName;
            ObjectId = objectId;
            ObjectName = objectName;
            Comment = comment;
            Items = new List<OperationLogItem>();
        }

        public void ChangeItems(List<OperationLogItem> items)
        {
            Items.AddRange(items);
        }
    }


    public class OperationLogItem : Entity<Guid>
    {
        public Guid OperationLogId { private set; get; }

        public string FieldName { private set; get; }

        public string FieldCaption { private set; get; }

        public string FieldOldValue { private set; get; }

        public string FieldOldCaptionValue { private set; get; }

        public string FieldNewValue { private set; get; }

        public string FieldNewCaptionValue { private set; get; }

        public string Comment { private set; get; }

        private OperationLogItem() { }

        public OperationLogItem(Guid id , Guid operationLogId, string fieldName, string fieldCaption, 
            object fieldOldValue, string fieldOldCaptionValue, object fieldNewValue, string fieldNewCaptionValue, string comment)
        {
            Id= id;
            OperationLogId = operationLogId;
            FieldName = fieldName;
            FieldCaption = fieldCaption;
            FieldOldValue = fieldOldValue?.ToString();
            FieldOldCaptionValue = fieldOldCaptionValue;
            FieldNewValue = fieldNewValue?.ToString();
            FieldNewCaptionValue = fieldNewCaptionValue;
            Comment = comment;
        }
    }

}
